<template>
  <div>
    <div class="conditionRow">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
       <el-form-item label="用户名" prop="userName">
         <el-input
           v-model="queryParams.userName"
           placeholder="请输入用户名"
           clearable
           @keyup.enter.native="handleQuery"
           @change="handleQuery"
         />
       </el-form-item>
       <el-form-item label="手机号" prop="phone">
         <el-input
           v-model="queryParams.phone"
           placeholder="请输入手机号"
           clearable
           @keyup.enter.native="handleQuery"
           @change="handleQuery"
         />
       </el-form-item>
       <el-form-item label="创建时间">
         <el-date-picker
           v-model="dateRange"
           style="width: 240px"
           value-format="yyyy-MM-dd"
           type="daterange"
           range-separator="-"
           start-placeholder="开始日期"
           end-placeholder="结束日期"
           @change="timeChange"
         ></el-date-picker>
       </el-form-item>
       <el-form-item>
         <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
         <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
       </el-form-item>
     </el-form>
    </div>
    <el-table
      v-loading="loading"
      :data="list"
      style="width: 100%;"
    >
      <el-table-column label="用户名" align="center" prop="userName" :show-overflow-tooltip="true" />
      <el-table-column label="手机号" align="center" prop="phone" :show-overflow-tooltip="true" />
      <el-table-column label="注册时间" align="center" prop="createdTime" :show-overflow-tooltip="true" />
      <el-table-column label="积分" align="center" prop="integral" :show-overflow-tooltip="true" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            type="primary"
            plain
            @click="handleForceLogout(scope.row)"
            v-hasPermi="['monitor:online:forceLogout']"
          >详情</el-button>
          <el-button
            type="primary"
            plain
            @click="addIntegral(scope.row)"
            v-hasPermi="['monitor:online:forceLogout']"
          >积分</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.currentPage"
      :limit.sync="queryParams.pageSize"
      layout="total, prev, pager, next,sizes,jumper"
      @pagination="getList"
    />
    <!-- 添加或修改回收订单对话框 -->
    <el-dialog title="用户详情" :visible.sync="openDetail" width="350px" append-to-body>
        <div class="contbox">
            <div class="boxrow">
              <div class="userrow1">
                <img class="userimg" :src="detailInfo.img" alt="">
                <span class="usertex">{{detailInfo.userName}}</span>
              </div>
            </div>
            <div class="boxrow"><span class="name">手机号：</span><p class="tex">{{detailInfo.visitTime}}</p></div>
            <div class="boxrow"><span class="name">积分：</span><p class="tex">{{detailInfo.integral}}</p></div>
        </div>
    </el-dialog>
    <el-dialog
      title="添加积分"
      :visible.sync="integralPopShow"
      width="350px"
      class="integralPop"
      center>
      <div class="integralIpt">
        <span>积分</span>
        <el-input type="number" v-model="integralnum" placeholder="请输入"></el-input>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="integralPopShow = false">取 消</el-button>
        <el-button type="primary" @click="integralSubmit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import { listClient, getClient, addSaveIntegral } from "@/api/user/client";
  export default {
      data(){
        return{
          // 显示搜索条件
          showSearch: true,
          // 查询参数
          queryParams: {
            currentPage: 1,
            pageSize: 10,
            userName: null,
            phone: null,
            searchTimeBegin: null,
            searchTimeEnd: null
          },
          // 日期范围
          dateRange: [],
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 表格数据
          list: [],
          currentPage: 1,
          pageSize: 10,
          openDetail:false,
          detailInfo:{},
          integralPopShow:false,
          integralnum:null
        }
      },
      created() {
        this.getList();
      },
      methods:{
        timeChange(time){
          if(time){
            this.queryParams.searchTimeBegin=time[0]
            this.queryParams.searchTimeEnd=time[1]
          }else{
            this.queryParams.searchTimeBegin=null
            this.queryParams.searchTimeEnd=null
          }
          this.handleQuery()
        },
        /** 查询列表 */
        getList() {
          this.loading = true;
          for(let i in this.queryParams){
            if(!this.queryParams[i]) this.queryParams[i]=null
          }
          listClient(this.queryParams).then(response => {
            this.list = response.records;
            this.total = response.total;
            this.loading = false;
          });
        },
        /** 搜索按钮操作 */
        handleQuery() {
          this.queryParams.currentPage = 1;
          this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
          this.resetForm("queryForm");
          this.queryParams.searchTimeBegin=''
          this.queryParams.searchTimeEnd=''
          this.dateRange=[]
          console.log(this.queryParams)
          this.handleQuery();
        },
        handleForceLogout(data){
          getClient(data.id).then(response=>{
             console.log(response)
             this.detailInfo=data
             this.openDetail=true
          })
        },
        addIntegral(data){
          this.integralPopid=data.id
          this.integralnum=null
          this.integralPopShow=true
        },
        integralSubmit(){
          let data={
            id:this.integralPopid,
            integral:this.integralnum
          }
          addSaveIntegral(data).then(response=>{
             this.integralPopShow=false
             this.$message({
               message: "添加成功",
               type: 'success'
             })
             setTimeout(()=>{
               this.getList()
             },1500)
          })
        }
      }
  }
</script>

<style lang="scss" scoped>
  .contbox{
    margin: 0 40px;
    .boxrow{
      display: flex;
      align-items: center;
      font-size: 14px;
      margin-bottom: 18px;
      color: #333;
      .name{
        font-weight: bold;
      }
      .tex{
        max-width: 350px;
      }
      .lump{
        display: flex;
        margin-right: 30px;
      }
      .img{
          max-width: 350px;
      }
      .userrow1{
        display: flex;
        align-items: center;
        .userimg{
          width: 60px;
          height: 60px;
          border-radius: 50%;
        }
        .usertex{
          color: #333;
          font-size: 14px;
          margin-left: 20px;
        }
      }
    }
  }
  .integralPop{
    .integralIpt{
      display: flex;
      justify-content: center;
      align-items: center;
      .el-input{
        width: 200px;
        margin-left: 10px;
      }
    }
  }
</style>
